//---------------------------------------------------------------------------

#ifndef t_mainformH
#define t_mainformH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <System.Actions.hpp>
#include <Vcl.ActnList.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.Dialogs.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.ImgList.hpp>
#include <Vcl.Menus.hpp>
#include <Vcl.MPlayer.hpp>
#include <Vcl.ToolWin.hpp>
#include <Vcl.Graphics.hpp>
//---------------------------------------------------------------------------
class HStage;
class HDesignControl;
class HPortal;
class HProgressBar;

const int HM_REFRESHCOMPLETE         = WM_USER + 101;
const int HM_ENTERBATCH              = WM_USER + 102;
const int HM_PROGRESS                = WM_USER + 103;

class TMainForm : public TForm
{
__published:	// IDE-managed Components
   TPageControl *PageControl1;
   TToolBar *ToolBar1;
   TToolButton *ToolButtonRefresh;
   TToolButton *ToolButtonHome;
   TToolButton *ToolButtonUp;
   TToolButton *ToolButtonList;
   TToolButton *ToolButton1;
   TPanel *PanelAttention;
   TLabel *Label1;
   TButton *ButtonOk;
   TMediaPlayer *MediaPlayer1;
   TImageList *ImageList1;
   TMainMenu *MainMenu1;
   TMenuItem *File1;
   TMenuItem *Refresh1;
   TMenuItem *Home1;
   TMenuItem *Up1;
   TMenuItem *List1;
   TMenuItem *ChangeSkin1;
   TMenuItem *N1;
   TMenuItem *Exit1;
   TMenuItem *Batch1;
   TMenuItem *EnterBatch1;
   TMenuItem *N8;
   TMenuItem *StartBatch1;
   TMenuItem *PauseBatch1;
   TMenuItem *ContinueBatch1;
   TMenuItem *StopBatch1;
   TMenuItem *N2;
   TMenuItem *Downloadsbtfile1;
   TMenuItem *SaveBatchStatus1;
   TMenuItem *BatchLoadBatchStatus1;
   TMenuItem *ViewBatchProperties1;
   TMenuItem *Analyze1;
   TMenuItem *ViewBatchSummary1;
   TMenuItem *CalculateCriticalPath2;
   TMenuItem *AnalyzeDrawGanttChar1;
   TMenuItem *DrawConcurrencyChart1;
   TMenuItem *Help1;
   TMenuItem *About1;
   TMenuItem *Legend1;
   TActionList *ActionList1;
   TAction *FileRefresh;
   TAction *FileExit;
   TAction *HelpAbout;
   TAction *BatchStart;
   TAction *BatchPause;
   TAction *BatchStop;
   TAction *FileHome;
   TAction *AnalyzeViewSummary;
   TAction *BatchResume;
   TAction *FileUp;
   TAction *FileList;
   TAction *FileChangeSkin;
   TAction *AnalyzeCalcCriticalPath;
   TAction *BatchGotoThis;
   TAction *BatchProperties;
   TAction *BatchDownload;
   TAction *HelpLegend;
   TAction *AnalyzeDrawGanttChart;
   TAction *BatchSaveStatus;
   TAction *BatchLoadStatus;
   TAction *AnalyzeDrawConcurrencyChart;
   TPopupMenu *PopupMenu1;
   TMenuItem *GoToThisGroup1;
   TMenuItem *N10;
   TMenuItem *Skip1;
   TMenuItem *Restore1;
   TMenuItem *Rerun1;
   TMenuItem *Stop1;
   TMenuItem *Restart1;
   TMenuItem *ChangeCondition1;
   TMenuItem *StopAndSkip1;
   TMenuItem *N5;
   TMenuItem *ViewLog1;
   TMenuItem *ViewAdditionalLog1;
   TMenuItem *ViewRestoreLog1;
   TMenuItem *N6;
   TMenuItem *FireThisEvent1;
   TPopupMenu *PopupMenu2;
   TMenuItem *Enter1;
   TMenuItem *N3;
   TMenuItem *StartBatch2;
   TMenuItem *PauseBatch2;
   TMenuItem *ContinueBatch2;
   TMenuItem *StopBatch2;
   TMenuItem *N4;
   TMenuItem *ViewSummary2;
   TMenuItem *CalculateCriticalPath1;
   TMenuItem *N7;
   TMenuItem *Downloadsbtfile2;
   TMenuItem *SaveBatchStatus2;
   TMenuItem *LoadBatchStatus1;
   TMenuItem *Properties1;
   TSaveDialog *SaveDialog1;
   TOpenDialog *OpenDialog1;
   TTimer *Timer1;
   TPanel *Panel1;
   TPanel *Panel2;
   TMenuItem *Breakpoint1;
   TToolButton *ButtonBackward;
   TToolButton *ButtonForward;
   TAction *FileBackward;
   TAction *FileForward;
   TMenuItem *Backward1;
   TMenuItem *Forward1;
   TAction *BatchRerunAll;
   TMenuItem *RerunAllFailedJobs1;
   void __fastcall FormShow(TObject *Sender);
   void __fastcall AnalyzeViewSummaryExecute(TObject *Sender);
   void __fastcall AnalyzeCalcCriticalPathExecute(TObject *Sender);
   void __fastcall AnalyzeDrawGanttChartExecute(TObject *Sender);
   void __fastcall AnalyzeDrawConcurrencyChartExecute(TObject *Sender);
   void __fastcall BatchStartExecute(TObject *Sender);
   void __fastcall BatchPauseExecute(TObject *Sender);
   void __fastcall BatchStopExecute(TObject *Sender);
   void __fastcall BatchResumeExecute(TObject *Sender);
   void __fastcall BatchGotoThisExecute(TObject *Sender);
   void __fastcall BatchPropertiesExecute(TObject *Sender);
   void __fastcall BatchDownloadExecute(TObject *Sender);
   void __fastcall BatchSaveStatusExecute(TObject *Sender);
   void __fastcall BatchLoadStatusExecute(TObject *Sender);
   void __fastcall FileRefreshExecute(TObject *Sender);
   void __fastcall FileExitExecute(TObject *Sender);
   void __fastcall FileHomeExecute(TObject *Sender);
   void __fastcall FileUpExecute(TObject *Sender);
   void __fastcall FileListExecute(TObject *Sender);
   void __fastcall FileChangeSkinExecute(TObject *Sender);
   void __fastcall HelpAboutExecute(TObject *Sender);
   void __fastcall HelpLegendExecute(TObject *Sender);
   void __fastcall FormDestroy(TObject *Sender);
   void __fastcall ActionList1Update(TBasicAction *Action, bool &Handled);
   void __fastcall PopupMenu1Popup(TObject *Sender);
   void __fastcall Skip1Click(TObject *Sender);
   void __fastcall Restore1Click(TObject *Sender);
   void __fastcall Rerun1Click(TObject *Sender);
   void __fastcall Stop1Click(TObject *Sender);
   void __fastcall Restart1Click(TObject *Sender);
   void __fastcall ChangeCondition1Click(TObject *Sender);
   void __fastcall StopAndSkip1Click(TObject *Sender);
   void __fastcall ViewLog1Click(TObject *Sender);
   void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
   void __fastcall MediaPlayer1Notify(TObject *Sender);
   void __fastcall ButtonOkClick(TObject *Sender);
   void __fastcall Timer1Timer(TObject *Sender);
   void __fastcall ViewAdditionalLog1Click(TObject *Sender);
   void __fastcall ViewRestoreLog1Click(TObject *Sender);
   void __fastcall FireThisEvent1Click(TObject *Sender);
   void __fastcall GoToThisGroup1Click(TObject *Sender);
   void __fastcall Breakpoint1Click(TObject *Sender);
   void __fastcall FileBackwardExecute(TObject *Sender);
   void __fastcall FileForwardExecute(TObject *Sender);
   void __fastcall BatchRerunAllExecute(TObject *Sender);

public:		// User declarations
        struct HInfo
        {
           UTF8String Author;
           UTF8String JobTrigger;
           UTF8String BatchTrigger;
           bool AutoSkip;
           UTF8String AutoRerun;
           UTF8String Description;
           UTF8String IncludeFiles;
           bool CheckBeforeTransfer;
           UTF8String FadingPeriod;
           UTF8String PartitionDither;
           UTF8String SectionList;
           UTF8String GroupName;
           bool AcrossDayEnd;
           UTF8String Banner;
           int BannerPosition;
           UTF8String BannerFontName;
           int BannerFontSize;
           int BannerFontStyle;
           UTF8String TrafficControl;
           HInfo()
              : AutoSkip(false), CheckBeforeTransfer(false),
                BannerPosition(0), BannerFontName("Arial"),
                BannerFontSize(8), BannerFontStyle(0), AcrossDayEnd(false)
           {}
        };
        HStage *SelectedStage;
        HPortal *Portal;
        UTF8String ErrorJobName;
        int InitWidth;
        int InitHeight;
        HProgressBar *ProgressBar;
        map<UTF8String, UTF8String> UpperGroupMap;

        __fastcall TMainForm(TComponent* Owner);
        void __fastcall GetInfo(HInfo &Info);
        void __fastcall RefreshCaption(void);
        void __fastcall Refresh(void);
        void __fastcall RemoveAll(void);
        void __fastcall LoadFromXmlTree(HXmlTree *XmlTree);
        void __fastcall RefreshFromXmlTree(HXmlTree *XmlTree);
        HDesignControl * __fastcall CurrentDesignControl(void);
        bool __fastcall GotoPage(const UTF8String &Group,
           int HScrollPosition = 0, int VScrollPosition = 0);
        void __fastcall SaveToJobList(map<UTF8String, HJobListInfo> &JobMap,
           bool CriticalFlag = false);
        void __fastcall SaveToBatList(map<int, HBatListInfo> &BatMap);
        void __fastcall SaveToPartTimeList(vector<HPartTimeInfo> &PartTimeVec);
        void __fastcall SaveToGanttList(const TDateTime &StartTime,
           const TDateTime &EndTime, bool PartitionFlag, int Time, vector<HGanttInfo> &Vec);
        bool __fastcall CurrentBatchIsRunning();
        bool __fastcall CurrentBatchIsCompleted();
        bool __fastcall CurrentBatchEnableRestart();
        bool __fastcall CurrentBatchShowBatchDate();
        HStage * __fastcall FindControlByName(const UTF8String &Name);
        void __fastcall ViewLog(const UTF8String &JobName);
        void __fastcall Skip(const UTF8String &JobName);
        void __fastcall Restore(const UTF8String &JobName);
        void __fastcall Rerun(const UTF8String &JobName);
        void __fastcall Stop(const UTF8String &JobName);
        void __fastcall StopAndSkip(const UTF8String &JobName);
        void __fastcall Restart(const UTF8String &JobName);
        bool __fastcall GotoGroupAndFocusToJob(const UTF8String &Name);
        void __fastcall ChangeCondition(const UTF8String &JobName);
        void __fastcall EnterBatch(const UTF8String &StatusFileName);
        void __fastcall Attention(const UTF8String &Caption, bool Error);
        void __fastcall ReloadUpperGroupMap();
        void __fastcall SaveNavInfo();
        void __fastcall TruncNavInfo();
        void __fastcall RefreshBatchColor(int ServerIdx);
private:	// User declarations
        void __fastcall NewGroup(const UTF8String &Name = "",
           HXmlTree *Node = NULL, bool XmlPropertyFlag = false,
           bool MakePageActive = true);
        bool __fastcall GroupExist(const UTF8String &Name);

        void __fastcall GotoPage(int Index);
        void __fastcall HMRefreshComplete(TMessage &Message);
        void __fastcall HMEnterBatch(TMessage &Message);
        void __fastcall HMProgress(TMessage &Message);
        void __fastcall OpenAttention(const UTF8String &WhistleFile);
        void __fastcall CloseAttention();
        void __fastcall DoNav(const HNavInfo &Info);

        struct HGroupInfo
        {
           TTabSheet *TabSheet;
           HDesignControl *DesignControl;
        };

        void __fastcall FuncHome(void);
        bool __fastcall CanHome(void);
        void __fastcall FuncUp(void);
        HInfo FInfo;
        vector<HGroupInfo> Groups;
        map<UTF8String, int> GroupMap;
        bool MediaOpened;

        vector<HNavInfo> NavVec;
        int NavIdx;

protected :
        BEGIN_MESSAGE_MAP
           VCL_MESSAGE_HANDLER(HM_REFRESHCOMPLETE, TMessage,
              HMRefreshComplete);
           VCL_MESSAGE_HANDLER(HM_ENTERBATCH, TMessage,
              HMEnterBatch);
           VCL_MESSAGE_HANDLER(HM_PROGRESS, TMessage,
              HMProgress);
        END_MESSAGE_MAP(TForm);
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
